/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：接口实现                                                    
*│　作    者：gaotang                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-01-04 09:55:38                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： BestTrader.Cms.Repository.SqlServer                                  
*│　类    名： ManagerDataRepository                                      
*└──────────────────────────────────────────────────────────────┘
*/
using BestTrader.Cms.Core.DbHelper;
using BestTrader.Cms.Core.Options;
using BestTrader.Cms.Core.Repository;
using BestTrader.Cms.IRepository;
using BestTrader.Cms.Models;
using Microsoft.Extensions.Options;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;

namespace BestTrader.Cms.Repository.SqlServer
{
    public class ManagerDataRepository : BaseRepository<ManagerData, Int32>, IManagerDataRepository
    {
        public ManagerDataRepository(IOptionsSnapshot<DbOption> options)
        {
            _dbOption = options.Get("BT.TEST");
            if (_dbOption == null)
            {
                throw new ArgumentNullException(nameof(DbOption));
            }
            _dbConnection = ConnectionFactory.CreateConnection(_dbOption.DbType, _dbOption.ConnectionString);
        }

        public IEnumerable<string> GetAuditImagesById(int id)
        {
            var items = GetList($"where ManagerId = { id } AND IsDelete=0");
            return items.Select(p => p.ImageUrl);
        }

        public async Task<IEnumerable<string>> GetAuditImagesByIdAsync(int id)
        {
            var items = await GetListAsync($"where ManagerId = { id } AND IsDelete=0");
            return items.Select(p => p.ImageUrl);
        }
        public Task<int> UpdateDeleteByManagerId(int ManagerId)
        {
            DateTime now = DateTime.Now;
            string sql = "update ManagerData set IsDelete=1,ModifyTime=@NowTime where ManagerId = @MId";
            var result = _dbConnection.ExecuteAsync(sql, new
            {
                NowTime=now,
                MId = ManagerId
            });
            return result;

        }


    }
}